package com.web.user;

import com.bean.User;
import com.service.UserService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegisterServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户信息
        User user=new User();
        //调用service
        UserService service=new UserService();

       try{
           BeanUtils.populate(user, req.getParameterMap());
           service.register(user);
           resp.sendRedirect(req.getContextPath() + "admin/login/home.jsp");
       }catch (Exception e){
           e.printStackTrace();
       }
    }
}
